package hk.ust.cse.comp3111.studentSchedule;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Course {

    //private variables
    private int classNo;
    private int structure;
    private int type;
    private String courseCode;
    private String section;
    private String courseName;
    private String venue;
    
    private Date fromDate;
    private Date endDate;
    
    //in millisecond from 00:00
    private long rep1_fromTime;
    private long rep1_toTime;
    private long rep2_fromTime;
    private long rep2_toTime;
    private long rep3_fromTime;
    private long rep3_toTime;
    
    //1 for Monday, 2 for Tue...
    private long rep1_weekDay=0;
    private long rep2_weekDay=0;
    private long rep3_weekDay=0;
    
     
    // Empty constructor
    public Course(){
    	
		SimpleDateFormat dateFormatting = new SimpleDateFormat("dd-MMM-yyyy");
		try {
			endDate = dateFormatting.parse("2014-05-09");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
         
    }
    
    
    // constructor for 3 rep
    public Course(int classNo, int structure, int type, String courseCode,
			String section, String courseName, String venue, String fromDate,
			long rep1_fromTime, long rep1_toTime, long rep2_fromTime,
			long rep2_toTime, long rep3_fromTime, long rep3_toTime,
			long rep1_weekDay, long rep2_weekDay, long rep3_weekDay) {
		super();
		
		//Handle about endDate
		SimpleDateFormat dateFormatting = new SimpleDateFormat("yyyy-MM-dd");
		try {
			endDate = dateFormatting.parse("2014-05-09");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//Handle about fromDate
		try {
			this.fromDate= dateFormatting.parse(fromDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
		
		this.classNo = classNo;
		this.structure = structure;
		this.type = type;
		this.courseCode = courseCode;
		this.section = section;
		this.courseName = courseName;
		this.venue = venue;
		this.rep1_fromTime = timeConvert(rep1_fromTime);
		this.rep1_toTime = timeConvert(rep1_toTime);
		this.rep2_fromTime = timeConvert(rep2_fromTime);
		this.rep2_toTime = timeConvert(rep2_toTime);
		this.rep3_fromTime = timeConvert(rep3_fromTime);
		this.rep3_toTime = timeConvert(rep3_toTime);
		this.rep1_weekDay = rep1_weekDay;
		this.rep2_weekDay = rep2_weekDay;
		this.rep3_weekDay = rep3_weekDay;
	}

    // constructor for 2 rep
    public Course(int classNo, int structure, int type, String courseCode,
			String section, String courseName, String venue, String fromDate,
			long rep1_fromTime, long rep1_toTime, long rep2_fromTime,
			long rep2_toTime, long rep1_weekDay, long rep2_weekDay) {
		super();
		
		//Handle about endDate
		SimpleDateFormat dateFormatting = new SimpleDateFormat("yyyy-MM-dd");
		try {
			endDate = dateFormatting.parse("2014-05-09");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//Handle about fromDate
		try {
			this.fromDate= dateFormatting.parse(fromDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
		
		this.classNo = classNo;
		this.structure = structure;
		this.type = type;
		this.courseCode = courseCode;
		this.section = section;
		this.courseName = courseName;
		this.venue = venue;
		this.rep1_fromTime = timeConvert(rep1_fromTime);
		this.rep1_toTime = timeConvert(rep1_toTime);
		this.rep2_fromTime = timeConvert(rep2_fromTime);
		this.rep2_toTime = timeConvert(rep2_toTime);
		this.rep1_weekDay = rep1_weekDay;
		this.rep2_weekDay = rep2_weekDay;
	}
     

    // constructor for 1 rep
    public Course(int classNo, int structure, int type, String courseCode,
			String section, String courseName, String venue, String fromDate,
			long rep1_fromTime, long rep1_toTime, long rep1_weekDay) {
		super();
		
		//Handle about endDate
		SimpleDateFormat dateFormatting = new SimpleDateFormat("yyyy-MM-dd");
		try {
			endDate = dateFormatting.parse("2014-05-09");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//Handle about fromDate
		try {
			this.fromDate= dateFormatting.parse(fromDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
		
		this.classNo = classNo;
		this.structure = structure;
		this.type = type;
		this.courseCode = courseCode;
		this.section = section;
		this.courseName = courseName;
		this.venue = venue;
		this.rep1_fromTime = timeConvert(rep1_fromTime);
		this.rep1_toTime = timeConvert(rep1_toTime);
		this.rep1_weekDay = rep1_weekDay;
	}
    
    
    
    
    
    
    
    
    public int getClassNo() {
		return classNo;
	}


	public void setClassNo(int classNo) {
		this.classNo = classNo;
	}


	public int getStructure() {
		return structure;
	}


	public void setStructure(int structure) {
		this.structure = structure;
	}
	
	public int getType() {
		return type;
	}


	public void setType(int type) {
		this.type = type;
	}	


	public String getCourseCode() {
		return courseCode;
	}


	public void setCourseCode(String courseCode) {
		this.courseCode = courseCode;
	}


	public String getSection() {
		return section;
	}


	public void setSection(String section) {
		this.section = section;
	}


	public String getCourseName() {
		return courseName;
	}


	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}


	public String getVenue() {
		return venue;
	}


	public void setVenue(String venue) {
		this.venue = venue;
	}


	public Date getFromDate() {
		return fromDate;
	}


	public void setFromDate(String fromDate) {
		SimpleDateFormat dateFormatting = new SimpleDateFormat("yyyy-MM-dd");
		try {
			this.fromDate = dateFormatting.parse(fromDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


	public long getRep1_fromTime() {
		return rep1_fromTime;
	}


	public void setRep1_fromTime(long rep1_fromTime) {
		this.rep1_fromTime = timeConvert(rep1_fromTime);
	}


	public long getRep1_toTime() {
		return rep1_toTime;
	}


	public void setRep1_toTime(long rep1_toTime) {
		this.rep1_toTime = timeConvert(rep1_toTime);
	}


	public long getRep2_fromTime() {
		return rep2_fromTime;
	}


	public void setRep2_fromTime(long rep2_fromTime) {
		this.rep2_fromTime = timeConvert(rep2_fromTime);
	}


	public long getRep2_toTime() {
		return rep2_toTime;
	}


	public void setRep2_toTime(long rep2_toTime) {
		this.rep2_toTime = timeConvert(rep2_toTime);
	}


	public long getRep3_fromTime() {
		return rep3_fromTime;
	}


	public void setRep3_fromTime(long rep3_fromTime) {
		this.rep3_fromTime = timeConvert(rep3_fromTime);
	}


	public long getRep3_toTime() {
		return rep3_toTime;
	}


	public void setRep3_toTime(long rep3_toTime) {
		this.rep3_toTime = timeConvert(rep3_toTime);
	}


	public long getRep1_weekDay() {
		return rep1_weekDay;
	}


	public void setRep1_weekDay(long rep1_weekDay) {
		this.rep1_weekDay = rep1_weekDay;
	}


	public long getRep2_weekDay() {
		return rep2_weekDay;
	}


	public void setRep2_weekDay(long rep2_weekDay) {
		this.rep2_weekDay = rep2_weekDay;
	}


	public long getRep3_weekDay() {
		return rep3_weekDay;
	}


	public void setRep3_weekDay(long rep3_weekDay) {
		this.rep3_weekDay = rep3_weekDay;
	}


	//convert 4 digit time to milliseconds(HH-SS only)
    public long timeConvert(long input){
		return 3600000L*(input/100L) + 60000L*(input%100L);
    }
    
    
    public boolean isNull(){
    	if(rep1_weekDay==0) return true;
    	else return false;
    }
    
    public List<String> getWeekDayInWords(){
    	
    	List<String> temp=new ArrayList<String>();
    	
    	if(this.rep2_weekDay==0){
			//one rep only
    		temp.add(changeToWord(this.rep1_weekDay));
		}
		
		else if (this.rep3_weekDay==0){
			//two rep
			temp.add(changeToWord(this.rep1_weekDay));
			temp.add(changeToWord(this.rep2_weekDay));
		}
		
		else {
			// three rep
			temp.add(changeToWord(this.rep1_weekDay));
			temp.add(changeToWord(this.rep2_weekDay));
			temp.add(changeToWord(this.rep3_weekDay));
		}
    	
    	return temp;
    	

    	
    }
    
    public String changeToWord(long input){
    	switch((int)input){
    	case 1:
    		return "Mon";
    	case 2:
    		return "Tue";
    	case 3:
    		return "Wed";
    	case 4:
    		return "Thu";
    	case 5:
    		return "Fri";
    	case 6:
    		return "Sat";
    	case 7:
    		return "Sun";
    		
    	}
		return null;
    		
    		
    		
    }
    
    public String[] milisToStringArray(long input){
    	int hr, minute;
    	input=(int)input/1000;
    	hr=(int) input/3600;
    	minute=(int)input%3600/60;
    	
    	String hrS,minS;
    	hrS=String.valueOf(hr);
    	minS=String.valueOf(minute);
    	
    	if(hrS.length()<2) hrS="0"+hrS;
    	if(minS.length()<2) minS=minS+"0";

    	return new String[]{hrS,minS};
    	
    }
    

	
	
	
}
